using AOT;
using GameMain.Utils;
using System;
using System.Runtime.InteropServices;
using UnityEngine;
using GameMain.HCLRExtTools;

namespace GameMain.Scripts
{
    public partial class GameRoot : MonoBehaviour
    {
        [MonoPInvokeCallback(typeof(RuntimeApi.LogDelegate))]
        public static void LogDelegateData(IntPtr pMsg, int iSize)
        {
            SimpleLog.Log(Marshal.PtrToStringAnsi(pMsg, iSize));
        }

        public static GameRoot Instance = null;
        private async void Awake()
        {
            RuntimeApi.HCLRExtTools_SetLogHandler(new RuntimeApi.LogDelegate(LogDelegateData));

            Instance = this;

            InitUI();

            var oldName = gameObject.name;
            gameObject.name = "ApplicationManager";

            if (await CheckResource())
            {
                return;
            }

            gameObject.name = oldName;
            await LoadGameDll();
            await RunDll();
        }
    }
}
